package com.wyx.suanfa;

/**
 * @author 王艺锡
 * @version 1.0
 */
/*public class generateMatrix {
    *//*给你一个正整数 n ，生成一个包含 1 到 n2 所有元素，
    且元素按顺时针顺序螺旋排列的 n x n 正方形矩阵 matrix 。
     *//*
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[][] ints = solution.generateMatrix(3);
        for (int i = 0; i < ints.length; i++) {
            System.out.println();
            for (int j = 0; j < ints.length; j++) {
                System.out.print(ints[i][j]);
            }
        }
    }
}*/
/*

class Solution {
    public int[][] generateMatrix(int n) {
        int arr[][] = new int[n][n];
        int startx = 0;
        int starty = 0;
        int offset = 1;
        int count = 1;
        int i = 0;
        int j = 0;
        int loop = 0;

        while (loop++ < n / 2) {
            //上边界
            for (j = starty; j < n - offset; j++) {
                arr[startx][j] = count++;
            }
            //右边界
            for (i = startx; i < n - offset; i++) {
                arr[i][j] = count++;
            }
            //下边界
            for (; j > startx; j--) {
                arr[i][j] = count++;
            }
            //左边界
            for (; i > starty; i--) {
                arr[i][j] = count++;
            }

            startx++;
            starty++;
            offset++;
        }

        if (n % 2 == 1) {
            arr[startx][starty] = count;
        }
        return arr;
    }
}
*/
